import Mock from 'better-mock';
import qs from 'query-string';
import dayjs from 'dayjs';
import setupMock from '@/utils/setupMock';
import * as Constants from '../constants';
const { list } = Mock.mock({
  'list|10': [
    {
      id: /[0-9]{8}[0-9]{4}/,
      name: () => Mock.Random.cword(10),
      'timeRanges|0-6': [
        {
          weekday: () => Mock.Random.pick(Constants.weekDays),
          start: () => Mock.Random.time('HH:mm'),
          end: () => Mock.Random.time('HH:mm'),
        },
      ],
    },
  ],
});

setupMock({
  mock: true,
  setup: () => {
    Mock.mock('/api/workPeriod/list', (params) => {
      const {
        page = 1,
        pageSize = 10,
        ...rest
      } = qs.parseUrl(params.url).query;
      const p = page as number;
      const ps = pageSize as number;

      const result = list;
      return {
        list: result.slice((p - 1) * ps, p * ps),
        total: result.length,
      };
    });
  },
});
